package com.uton.rfidcontroller.viewmodel.activity_model;

import com.uton.rfidcontroller.common.rfid.UfhData;
import com.uton.rfidcontroller.common.utils.LogUtil;
import com.uton.rfidcontroller.viewmodel.base.BaseViewModel;

/**
 * Created by 王家宝 on 2017/9/11.
 * Email:639586819@qq.com
 * Tel:18241150668
 */

public abstract class SettingViewModel extends BaseViewModel {

    private int tty_speed = 57600;
    private byte addr = (byte) 0xff;

    @Override
    public void refreshData() {

    }

    public void openScan() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                int result = UfhData.UhfGetData.OpenUhf(tty_speed, addr, 4, 0, null);
                LogUtil.d("打开设备的返回码" + result);
                if (result == 0) {
                    UfhData.UhfGetData.GetUhfInfo();
                    sendOpenMessage();
                }
            }
        }).start();
    }

    public void closeScan() {
        if (UfhData.isDeviceOpen()) {
            int result = UfhData.UhfGetData.CloseUhf();
            LogUtil.d("关闭设备的返回码" + result);
            if (result == 0) {
                sendCloseMessage();
            }
        }
    }

    public abstract void sendOpenMessage();

    public abstract void sendCloseMessage();

}
